<?php
/**
 * validator工厂类
 *
 * @package util.validator
 * @since 0.2
 */
class IValidatorFactory {
	private static $instance;
	private $validators = array();
	
	/**
	 * 构造器
	 *
	 * @since 0.2
	 */
	private function __construct() {
		
	}
	
	/**
	 * 取得实例
	 *
	 * @return IValidatorFactory
	 * @since 0.2
	 */
	public static function getInstance() {
		if (self::$instance == null) {
			self::$instance = new IValidatorFactory();
		}
		return self::$instance;
	}
	
	/**
	 * 添加校验器
	 *
	 * @param IValidator $validator
	 * @since 0.2
	 */
	public function addValidator(IValidator $validator) {
		$this->validators[] = $validator;
	}
	
	/**
	 * 取得所使用的校验器列表
	 *
	 * @return array
	 * @since 0.2
	 */
	public function getValidators() {
		return $this->validators;
	}
	
	/**
	 * 取得校验器产生的所有信息
	 *
	 * @return array
	 * @since 0.2
	 */
	public function getMessages() {
		$messages = array();
		foreach ($this->validators as $validator) {
			$messages[] = $validator->getMessages();
		}
		return $messages;
	}
}


?>